<template>
	<view class="container">
		<u-index-list :scrollTop="scrollTop" :index-list="indexList">
			<view v-for="(item,index) in indexList" :key='index'>
				<u-index-anchor :index="item" />
				<view class="list-cell" v-for="(i,idx) in brandList[item]" :key="idx" @click="select(i)">
					{{i.brandTitle}}
				</view>
			</view>
		</u-index-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				brandList: '',
				scrollTop: 0,
				indexList: []
			}
		},
		mounted() {
			this.getBrand()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			getBrand() {
				this.$u.api.brandSort().then(res => {
					if (res.code == 0) {
						for (var Key in res.data) {
							this.indexList.push(Key);
						}
						this.indexList.sort();
						this.brandList = res.data;
					}
				})
			},
			select(i){
				let pages = getCurrentPages();
				let currPage = pages[pages.length-2];
				currPage.$vm.brandName = i.brandTitle;
				currPage.$vm.form.productBrandId = i.id;
				uni.navigateBack();
			}
		}
	}
</script>

<style scoped lang="scss">
	.list-cell {
		display: flex;
		box-sizing: border-box;
		width: 100%;
		padding: 10px 24rpx;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
		border: 1px solid #f2f2f2;
	}
</style>
